import time
from TinyYShop_login import Tinyshop_Login

# 商品咨询
class Consult:
    def __init__(self):
        self.driver=Tinyshop_Login().login("123@qq.com","123456")
    def consult(self,value,pw):
        self.driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[2]/form/button").click()
        self.driver.find_element_by_xpath('/html/body/div[3]/div[2]/div/div/div[2]/dl/dd/ul/li[3]/dl').click()
        self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/ul/li[3]").click()
        self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div[3]/form/div/div[1]/textarea").clear()
        self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div[3]/form/div/div[1]/textarea").send_keys(value)
        self.driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div[3]/form/div/div[2]/span[1]/input').clear()
        self.driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div[3]/form/div/div[2]/span[1]/input').send_keys(pw)
        self.driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div[3]/form/div/div[2]/span[2]/input[1]').click()

    def consult_succ(self,expect):  #咨询发布成功
        if expect in self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[2]/div[2]/div/div/div/div/div[3]/div/div[1]/div[1]/div[1]/div[2]").text:
            print("case pass")
        else:
            print('fail')
            self.driver.quit()

    def consult_fail(self,expect):  #咨询发布失败
        if expect=="内容不能为空" or expect=="验证码不能为空":
            if expect in self.driver.find_element_by_xpath("/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div").text:
                print("reason is:%s"%expect)
        else:
            print("fail")
            self.driver.quit()


